<template>
    <view>
        <uni-nav-bar fixed left-icon="back" title="常见问题"></uni-nav-bar>
        <view style="margin: 20rpx 0">
            <scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadMore">
                <view class="t_content" v-for="(item, index) in list" :key="index">
                    <view class="t_name">{{item.name}}</view>
                    <view class="t_text">{{item.answer}}</view>
                </view>
            </scroll-view>
        </view>
        <view v-if="list.length" class="cu-load text-gray" :class="loadStatus"></view>
        <!-- 登录提示 -->
        <uni-login-model></uni-login-model>
    </view>
</template>

<script>
    import uniLoginModel from '@/components/uni-login-model/uni-login-model.vue'

    export default {
        name: "problem.vue",
        components: {
            uniLoginModel
        },
        data() {
            return {
                list: [],
                listQuery: {
                    pageNum: 1,
                    pageSize:10,
                },
                lastPage: 1,
                loadStatus: ''
            }
        },
        onReachBottom() {
            if (this.listQuery.pageNum < this.lastPage) {
                this.listQuery.pageNum += 1
                this.getList()
            }
        },
        onLoad() {
            this.getList()
        },
        methods: {
            getList() {
                uni.showLoading()
                this.loadStatus = 'loading'
                this.listQuery = {
                    ...this.listQuery,
                    pageNum: this.listQuery.pageNum
                }
                this.$api.api('program.list', this.listQuery).then(res => {
                    /*this.list = res.data.list*/
                    if (res.code == 200) {
                        // that.list = res.data.list
                        res.data.list.forEach(item=>{
                            this.list.push(item);
                        })
                        this.lastPage = res.data.totalPage
                        if (this.listQuery.pageNum < res.data.totalPage) {
                            this.loadStatus = ''
                        } else {
                            this.loadStatus = 'over'
                        }
                    } else {
                        this.$api.msg(res.message)
                    }
                    uni.hideLoading();
                }).catch(error => {
                    uni.hideLoading();
                })
            },
            //	加载更多
            loadMore() {
                if (this.listQuery.pageNum < this.lastPage) {
                    this.listQuery.pageNum += 1
                    this.loadData()
                }
            },
        }
    }
</script>

<style lang="scss" scoped>
.t_content {
    padding: 30rpx;
    background: #fff;
    border-bottom: 2rpx solid #eee;
    .t_name {
        font-size: 38rpx;
    }
    .t_text {
        color: #999;
        font-size: 36rpx;
    }
}
</style>